package com.movie.demo.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.movie.demo.pojo.Order;
import com.movie.demo.pojo.vo.OrderInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
@Repository
public interface OrderMapper extends BaseMapper<Order> {
    @Select("SELECT f.oid,g.cname, b.chinese_name,b.type,b.length,d.time,b.price,e.r_name,a.seat,c.account,c.userphone,f.state,f.create_time,f.sid\n" +
            " from seat a,movie b,user c ,arrange d, room e,orders f,cinema g\n" +
            "WHERE a.room_id=e.id and a.cinema_id=g.cid and a.session_id=d.id and f.sid=a.id and\n" +
            "f.uid=c.uid and a.mid=b.mid")
    List<OrderInfo> getAllInfo();

    @Select("SELECT f.oid,g.cname,b.chinese_name,b.type,b.length,d.time,d.id, b.price,e.r_name,a.seat,c.account,c.userphone,f.state,f.create_time,f.sid\n" +
            " from seat a,movie b,user c ,arrange d, room e,orders f,cinema g\n" +
            " WHERE a.room_id=e.id and a.cinema_id=g.cid and a.session_id=d.id and f.sid=a.id and\n" +
            " f.uid=c.uid and a.mid=b.mid and c.uid=#{id}")
    List<OrderInfo> getUserorder(int id);
    @Delete("delete from orders where oid=#{oid}")
    boolean deleteOrder(Integer oid);

    @Update("update seat a,movie b,user c ,arrange d, room e,orders f,cinema g set g.cname=#{cname},b.chinese_name=#{chinese_name},b.type=#{type},\n"+
            "b.length=#{length},d.time=#{time},b.price=#{price},e.r_name=#{r_name},a.seat=#{seat},c.account=#{account},c.userphone=#{phone},f.state=#{state},\n"+
            "f.create_time=#{create_time} where a.room_id=e.id and a.cinema_id=g.cid and a.session_id=d.id and f.sid=a.id and f.uid=c.uid and d.mid=b.mid and f.oid=#{oid}")
    boolean updateOrder(Integer oid,String cname,String chinese_name, String type,String length, String time, float price, String r_name,
                        String seat, String account, String phone, Integer state,Date create_time);

}
